﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _59结构体练习Vector2
{
    internal struct Vector2
    {
        public float X { get; set; }
        public float Y { get; set; }

        //构造函数
        public Vector2(float X, float Y)
        {
            this.X = X;
            this.Y = Y;
        }

        //求距离的静态方法
        public static float Distance(Vector2 p1, Vector2 p2)
        {
            float deltaX = p1.X - p2.X;
            float deltaY = p1.Y - p2.Y;

            return (float)Math.Sqrt(deltaX * deltaX + deltaY * deltaY);
        }
        //求距离的非静态方法
        public float Distance(Vector2 other)
        {
            return Distance(this, other);
        }
        //长度属性
        public float Length
        {
            get
            {
                return (float)Math.Sqrt(X * X + Y * Y);
            }
        }
    }
}